jQuery(document).ready(function($) {





/*
	$('div.promo a.next, .bg_promo a.prev').click(function(event) {
		event.preventDefault();

		var defineClickButton = ($(this).hasClass("next"))?1:0;

		var nowActive = $('.bg_promo .scroll-list .holl ul li:visible');

		var active = (defineClickButton) ?

			nowActive.next('li').size() ? nowActive.next('li') : $('div.promo ul.slideList li:first')
		:
			nowActive.prev('li').size() ? nowActive.prev('li') : $('div.promo ul.slideList li:last')
		;

		nowActive.hide();

		active.show();
	});*/

var nowGoAnimation = 0;

var promo = {

	



		manageSlide : function(){



			this.masSlide.parent().find('li.active').removeClass("active");
			$(this.masSlide[this.indexCurrentElement]).addClass("active");


			this.masPoint.parent().find('a.active').removeClass("active");
			$(this.masPoint[this.indexCurrentElement]).addClass("active");




				//-------------3-----------



					if(this.indexOldElement <  this.indexCurrentElement){
						var i_val = this.indexOldElement+1;
						var i_length_val = this.indexCurrentElement;
					}else{
						var i_val = this.indexCurrentElement+1;
						var i_length_val = this.indexOldElement;
					}

					for(var i = i_val; i < i_length_val; i++){



						$(this.masSlide[i]).css({
							'display':'none'
						});
						

					}


					this.indexCurrentElement = $($('div.promo ul.slideList li').not(":hidden")).index($('div.promo ul.slideList li.active'));

					if(this.indexOldElement >  this.indexCurrentElement){
						this.masSlide.parent().css({
							'margin-left' : -((this.indexCurrentElement+1) * this.widthSliders) + 'px'

						});
					}
					var t = this;



				//----------------\3-----------------
				//-----------------2------------------



					var margin = "-" + (this.indexCurrentElement * this.widthSliders) + 'px';


					nowGoAnimation = 1;
					 $(this.masSlide.parent()).animate(
							{
								marginLeft:  margin
							},
							"fast",
							function(){
							//-------------3-----------

								t.indexCurrentElement = $('div.promo ul.slideList li').index($('div.promo ul.slideList li.active'));



								t.indexOldElement = t.indexCurrentElement;

								t.masSlide.parent().css({
									'margin-left' : -((t.indexCurrentElement) * t.widthSliders) + 'px'

								});
								t.masSlide.css({
										'display' : 'block'
								});

						  //----------------\3-----------------
							nowGoAnimation = 0;
							}
						);
				//-----------------\2------------------






		},




		addEvent : function (){



			var t = this.t;

			$('div.navPoint div.listPoint a').click(function(event){
				if(nowGoAnimation) return false;
				event.preventDefault();
				t.thisElement = $(this);



				t.indexCurrentElement = t.masPoint.index(this);
				





				t.manageSlide();
			});

			$('div.promo a.next, .bg_promo a.prev').click(function(event){
				if(nowGoAnimation) return false;
				event.preventDefault();
				t.thisElement = $(this);



				var activeElement = t.masPoint.index(t.masPoint.parent().find('a.active'));




					t.indexCurrentElement = ($(this).hasClass("next")) ?
						(activeElement >= 9) ? 0 : (activeElement+1)
					:
						(activeElement <= 0) ? 9 : (activeElement-1)
					;



				t.manageSlide();
			});
		},



		_init : function(){



			this.thisElement = 'undefined';

			this.t = this;

			this.masSlide = $('div.promo ul.slideList li');
			this.masPoint =  $('div.navPoint div.listPoint a');



			var rnd = Math.floor(Math.random() * (this.masSlide.size() - 1));
			$(this.masSlide[rnd]).addClass("active");
			$(this.masPoint[rnd]).addClass("active");



			this.indexCurrentElement = $('div.promo ul.slideList li').index($('div.promo ul.slideList li.active'));
			this.indexOldElement = this.indexCurrentElement;




// --------------------2--------------------
			this.countSliders = this.masSlide.size();
			this.widthSliders = this.masSlide.width();
			this.masSlide.parent().css({
				'width': (this.widthSliders*this.countSliders),
				'margin-left': -this.widthSliders*this.indexCurrentElement
			});
			this.masSlide.css({'float':'left'});


// ----------------------------------------


			this.addEvent();

		}




	}

	promo._init();




/*
	$('.bg_promo .scroll-list .prev').click(function(event) {
		event.preventDefault();

		active = $('.bg_promo .scroll-list .holl ul li:visible')

		active = active.prev('li').size() ? active.prev('li') : $('.bg_promo .scroll-list .holl ul li:last');

		$('.bg_promo .scroll-list .holl ul li').hide();

		active.show();
	});*/


	














	$('.made-project .scroll-list .holl ul li:eq(' + Math.floor(Math.random() * ($('.made-project .scroll-list .holl ul li').size() - 1)) + ')').show();

	$('.made-project .scroll-list .next').click(function(event) {
		event.preventDefault();

		active = $('.made-project .scroll-list .holl ul li:visible')

		active = active.next('li').size() ? active.next('li') : $('.made-project .scroll-list .holl ul li:first');

		$('.made-project .scroll-list .holl ul li').hide();

		active.show();
	});

	$('.made-project .scroll-list .prev').click(function(event) {
		event.preventDefault();

		active = $('.made-project .scroll-list .holl ul li:visible')

		active = active.prev('li').size() ? active.prev('li') : $('.made-project .scroll-list .holl ul li:last');

		$('.made-project .scroll-list .holl ul li').hide();

		active.show();
	});

	$('.partners dt').click(function(event) {
		$(this).next().toggle(0);
	});

	$('.docs h4').click(function(event) {
		$(this).next().toggle(0);
	});

	$('.faq h3').click(function(event) {
		$(this).next().toggle(0);
	});

});